<!--

/*
* Copyright (C) 2005-2013 University of Sydney
*
* Licensed under the GNU License, Version 3.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.gnu.org/licenses/gpl-3.0.txt
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

/**
* brief description of file
*
* @author      Tom Murtagh
* @author      Kim Jackson
* @author      Ian Johnson   <ian.johnson@sydney.edu.au>
* @author      Stephen White   <stephen.white@sydney.edu.au>
* @author      Artem Osmakov   <artem.osmakov@sydney.edu.au>
* @copyright   (C) 2005-2013 University of Sydney
* @link        http://Sydney.edu.au/Heurist
* @version     3.1.0
* @license     http://www.gnu.org/licenses/gpl-3.0.txt GNU License 3.0
* @package     Heurist academic knowledge management system
* @subpackage  !!!subpackagename for file such as Administration, Search, Edit, Application, Library
*/

-->

<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>Heurist blog</title>
<link rel=stylesheet href="woot.css">
<link rel=stylesheet href="comments.css">
<link rel=stylesheet href="../../common/css/autocomplete.css">

<script src="../../external/jquery/jquery.js"></script>

<!-- to remove this absolte stuff
<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAGZugEZOePOFa_Kc5QZ0UQRQUeYPJPN0iHdI_mpOIQDTyJGt-ARSOyMjfz0UjulQTRjpuNpjk72vQ3w"></script>
-->

<!--script src="http://yui.yahooapis.com/2.5.2/build/yahoo/yahoo-min.js"></script>
<script src="http://yui.yahooapis.com/2.5.2/build/event/event-min.js"></script>
<script src="http://yui.yahooapis.com/2.5.2/build/history/history-debug.js"></script-->
<script src="../../external/yui/2.8.2r1/build/yahoo/yahoo-min.js"></script>
<script src="../../external/yui/2.8.2r1/build/event/event-min.js"></script>
<script src="../../external/yui/2.8.2r1/build/history/history-debug.js"></script>

<!-- scripts for dynamic map popup
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript" src="../../records/edit/digitizer/digitizer.js"></script>
<script type="text/javascript" src="../../external/timemap.2.0/lib/mxn/mxn.js?(googlev3)"></script>
<script type="text/javascript" src="../../external/timemap.2.0/lib/markerclusterer.js"></script>
<script type="text/javascript" src="../../external/timemap.2.0/src/timemap.js"></script>
<script type="text/javascript" src="../../viewers/map/mapping.js"></script>
 -->
<script type="text/javascript" src="../../common/js/hintDiv.js"></script> <!-- for mapviewer roolover -->

<script type="text/javascript" src="../../records/comments/threadedComments.js"></script>
<script type="text/javascript" src="../../external/tinymce/jscripts/tiny_mce/tiny_mce.js"></script>

<link rel="stylesheet" type="text/css" href="../../external/yui/2.8.2r1/build/fonts/fonts-min.css">
<link rel="stylesheet" type="text/css" href="../../common/css/global.css">
<link rel="stylesheet" type="text/css" href="../../common/css/search.css">
<link rel="stylesheet" type="text/css" href="../../common/css/blog.css">


</head>
<body>
 <input id=yui-history-field type=hidden>

<script type="text/javascript" src="../../common/js/utilsLoad.js"></script>
<script type="text/javascript" src="../../common/js/utilsUI.js"></script>

<script type="text/javascript" src="../../common/php/displayPreferences.php"></script>
<script type="text/javascript" src="../../common/php/loadCommonInfo.php"></script>
<script type="text/javascript" src="../../common/php/getMagicNumbers.php"></script>
<script type="text/javascript" src=autocompleteBlogTags.js></script>

<script type="text/javascript" src="../../common/php/loadHAPI.php"></script>
<script type="text/javascript" src="../../hapi/js/goi.js"></script>
<script type="text/javascript" src="../../records/woot/woot.js"></script>

<script type="text/javascript" src="../../records/edit/digitizer/mapViewer.js"></script>

<script>
	if (!(HCurrentUser && HCurrentUser.isLoggedIn())) {
		window.location = HAPI.XHR.defaultURLPrefix + "common/connect/login.php" + (HAPI.database ? "?db="+HAPI.database : "");
	}
</script>


<script src="blog.js"></script>

<script>

$(document).ready(function() {
	var user, group, record_type, query, matches;


	//
	// similar in search.js
	//
	function createUsedRectypeSelector(useIDs) {
		var rectypes = top.HEURIST.rectypes;
		var rectypeValSelect = document.getElementById("record-type");
		rectypeValSelect.innerHTML = '<option value="" selected>Any record type</option>';
		rectypeValSelect.onchange = function(){
			if(user || group){
				window.location.href = "?" + (user ? "u="+user.getID() : "g="+group.getID()) + "&t="+this.value +"db=" + HAPI.database;
			}
		}
		// rectypes displayed in Groups by group display order then by display order within group
		for (var index in rectypes.groups){
			if (index == 'groupIDToIndex' || top.HEURIST.rectypes.groups[index].showTypes.length < 1){
				continue;
			}
			var grp = document.createElement("optgroup");
			var firstInGroup = true,
				i=0;
			grp.label = rectypes.groups[index].name;
			for (; i < rectypes.groups[index].showTypes.length; i++) {
				var recTypeID = rectypes.groups[index].showTypes[i];
				if (recTypeID && rectypes.usageCount[recTypeID]) {
					if (firstInGroup){
						rectypeValSelect.appendChild(grp);
						firstInGroup = false;
					}
					var name = rectypes.names[recTypeID];
					var value =  (useIDs ? recTypeID : '"'+name+'"');
					var opt = new Option(name,value);
					$(opt).attr("rectype",recTypeID);
					$(opt).attr("title","" + rectypes.usageCount[recTypeID] + " records");
					rectypeValSelect.appendChild(opt);
				}
			}
		}
	}


	matches = location.href.match(/[?&]u=(\d+)/);	// extract the userID from the URI
	if (matches) {
		user = HUserManager.getUserById(matches[1]);
		$("#bloglogo a").attr("href", "?u=" + matches[1] + (database ? "&db="+database : ""));
	}
	if (! user) {
		matches = location.href.match(/[?&]g=(\d+)/);	// extract the groupID from the URI
		if (matches) {
			group = HWorkgroupManager.getWorkgroupById(matches[1]);
			$("#bloglogo a").attr("href", "?g=" + matches[1] + (database ? "&db="+database : ""));
		}
	}
	if (! (user || group)) { alert("user / group ID invalid or not provided"); return; }

	matches = location.href.match(/[?&]t=(\d+)/);	// extract the typeID from the URI
	if (matches) {
		record_type = HRecordTypeManager.getRecordTypeById(matches[1]);
	}

	matches = location.href.match(/[?&]q=([^&]+)/);
	if (matches) {
		query = unescape(matches[1]).replace(/\+/, ' ');
	}

	if (! record_type  &&  ! query) {
		record_type = HRecordTypeManager.getRecordTypeById(top.HEURIST.magicNumbers.RT_BLOG_ENTRY);	// blog entry record type
	}

	if (user) {
		$("#blog-owner").text(user.getRealName());
		document.title += " - " + user.getRealName();
	} else {
		$("#blog-owner").text(group.getName());
		document.title += " - " + group.getName();
	}

	var nameSort = function(a,b) {
		var x = a.getName().toLowerCase();
		var y = b.getName().toLowerCase();
		return (x == y) ? 0 : ((x > y) ? 1 : -1);
	};

	// blog select - ART: this code does not work in Chrome
/*
	$("<option value='u=" + HCurrentUser.getID() + "'>" + HCurrentUser.getRealName() + "</option>")
		.click(function () {
			location.href = "?" + this.value  + (database ? "&db="+database : "");
		})
		.appendTo("#blog-select");
	var wgs = HCurrentUser.getWorkgroups();
	wgs = wgs.sort(nameSort);
	for (var i = 0; i < wgs.length; ++i) {
		$("<option value='g=" + wgs[i].getID() + "'>" + wgs[i].getName() + "</option>")
			.click(function () {
				location.href = "?" + this.value + (database ? "&db="+database : "");
			})
			.appendTo("#blog-select");
	}
*/
	$("<option value='u=" + HCurrentUser.getID() + "'>" + HCurrentUser.getRealName() + "</option>")
		.appendTo("#blog-select");
	var wgs = HCurrentUser.getWorkgroups();
	wgs = wgs.sort(nameSort);
	for (var i = 0; i < wgs.length; ++i) {
		$("<option value='g=" + wgs[i].getID() + "'>" + wgs[i].getName() + "</option>")
			.appendTo("#blog-select");
	}

	$('#blog-select').change(function() {
		if(this.value){
			location.href = "?" + this.value  + (database ? "&db="+database : "");
		}
	});

	// record type select
	createUsedRectypeSelector(true);
	$("#record-type").val(query ?  0 : ( record_type?record_type.getID() :HRecordTypeManager.getRecordTypeById(top.HEURIST.magicNumbers.RT_BLOG_ENTRY)));

	/* old way
	var rectypes = HRecordTypeManager.getRecordTypes().sort(nameSort);
	for (var i = 0; i < rectypes.length; ++i) {
		$("<option value='" + rectypes[i].getID() + "'>" + rectypes[i].getName() + "</option>").appendTo("#record-type");
	}*/


	// later?
	var search = {};
	matches = location.hash.match(/^#((\d+)|(\d{4}-\d{2})|tag:(.*))$/);
	if (matches) {
		if (matches[2]) search["record"] = matches[2];
		else if (matches[3]) search["date"] = matches[3];
		else if (matches[4]) search["tag"] = matches[4];
	}

	$("#add-fav").append("<br>" + HCurrentUser.getRealName() + " : <a href='"+ (hBase ? hBase : HAPI.HeuristBaseURL) +"common/connect/login.php?logout=1" + (database ? "&db="+database : "")+"'>log out</a>");
	//$("#add-fav-link")[0].href += "&t=" + encodeURIComponent(document.title) + "&u=" + encodeURIComponent(window.location.href) + (database ? "&db="+database : "");

	if ((user  &&  HCurrentUser == user) ||
		(group  &&  HCurrentUser.isInWorkgroup(group))) {
		$("<input type='button' id='new-entry-button' value='New " + record_type.getName() + "'/>")
			.click(function() { Blog.newEntry(); })
			.insertAfter("#blog-owner");
	}

	$("#spiel,#hide-spiel-link").hide();
	$("#spiel,#spiel-leader").click(toggleSpiel);
	$("#show-spiel-link,#hide-spiel-link").click(function() { toggleSpiel(); return false; });

	window.onbeforeunload = function() {
		// check for existence of save and cancel buttons to determine if we're editing an entry
		if ($(".save-cancel-button-row").length) {
			return "Changes to the blog entry you are editing will not be saved.";
		} else {
			return null;
		}
	};


	document.getElementById("home-link").href = HAPI.XHR.defaultURLPrefix + "index.php?db=" +HAPI.database;

	var opts = { "type" : record_type };
	if (query) opts.query = query;
	if (user) opts.user = user;
	else if (group) opts.group = group;

	Blog.init(opts);


}); //document ready


function toggleSpiel() {
	$("#spiel").slideToggle("slow", function() {
		$("#show-spiel-link,#hide-spiel-link").toggle();
	});
}

function reload() {
	location.reload();
}

</script>


<!--

div class="tooltip" id="mapPopup"><p></p></div -->

<a id="home-link" href="#">
<div title="Click the logo at top left of any Heurist page to return to your Favourites" id="logo"></div>
</a>
<div id=version></div>
<!-- database name -->
<div id=dbname ></div>
<div id=sidebar>
	<div class=banner>
		<div id="add-fav"><!-- <a id=add-fav-link href="../../records/add/addRecordPopup.php?addref=1&amp;k=Favourites">Add page to favourites</a>--> </div>
	</div>

	<div id="sidebar-inner">
	<div id="right">
		<div class=detailRow>
		Show<select id=record-type><option value=0 disabled>(search results)</option></select>
		<!-- <input type="button" value="&lt;&lt; Back" onClick="history.go(-1);"> -->
		</div>
		<div class="detailRow">
			<div id="tags"></div>
		</div>
		<div class="detailRow">
			<div id="archives"><h4>Archives</h4></div>
		</div>
	</div></div>
</div>
<div id=spiel-leader><strong>Heurist Blog: the blog with more ...</strong> <a id=show-spiel-link href="#">tell me</a><a id=hide-spiel-link href="#">hide</a>
	<div id=spiel title="click to hide">
		  <br>
		  In most blogs a blog entry is just that - a blog entry, nothing more. In
		  Heurist, a blog entry is a fully-fledged record in a Heurist database.
		  That means you can re-use the data in many other ways:
		  <ul>
		   <li>
		    Create relationships between a blog entry and people, events,
		    bibliographic references or any of the other 70+ record types in Heurist;
		   </li>
		   <li>
		    See all the entries related to each entry in your blog, view them
		    as a blog, add a new related entry
		   </li>
		   <li>
		    View any type of record in blog format, edit, add related records etc.
		   </li>
		   <li>
		    Attach geographic and time locations to your blog entries (and
		    create maps and timelines from them);
		   </li>
		   <li>
		    Attach thumbnail images to your blog entries;
		   </li>
		   <li>
		    Use Heurist's search and publishing engine to find, reformat and
		    publish blog entries live to other web pages, or provide RSS feeds;
		   </li>
		   <li>
		    Insert other Heurist records in the blog entry as dynamic content
		    (including images and other media objects, bibliographic references,
		    people, places, events etc.);
		   </li>
		   <li>
		    Create extended blog entries with granular permissions (read and/or
		    write) on individual paragraphs down to individual users or workgroups;
		   </li>
		   <li>
		    Use a personal blog or a workgroup blog, show or hide records from a
		    broader public
		   </li>
		   <li>
		    Include records seamlessly in your personal blog simply by bookmarking
		   </li>
		  </ul>
		  <p>
		   For maximum control of a blog entry, click on 'Edit full record' link
		  </p>
		 </div>
       </div>

<div id=page>
<div id=header></div>

<div class=banner>
	<div style="display:table">
        <h1 id="blog-owner" class="tableCell"></h1>
    </div>
    <div id="blog-rss">
    	<a href="#" id="result-style-icons-link" title="Data feed, drag to bookmarks or a feed reader" target="_blank">
					<img src="../../common/images/logo_rss_feed.png"/></a>
	</div>
    <div id="blog-selector">Other blogs <select id="blog-select" style="max-width:200px"><option selected>select...</option></select></div>



	</div>
	<div id=page-inner>
  <div id=main></div>
  </div>

</div>

</body>
</html>
